/*     */ package com.zimbra.cs.octosync;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.mailbox.Document;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.OperationContext;
/*     */ import java.io.InputStream;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class BlobAccessViaMailbox
/*     */   implements BlobAccess
/*     */ {
/*     */   private Mailbox mbox;
/*     */   private OperationContext opContext;
/*     */   private int defaultFileId;
/*     */   private int defaultVersion;
/*     */   
/*     */   public BlobAccessViaMailbox(Mailbox mbox, OperationContext opContext, int defaultFileId, int defaultVersion)
/*     */   {
/*  55 */     this.mbox = mbox;
/*  56 */     this.opContext = opContext;
/*  57 */     this.defaultFileId = defaultFileId;
/*  58 */     this.defaultVersion = defaultVersion;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public int[] getActualReference(int fileId, int version)
/*     */   {
/*  65 */     int[] result = new int[2];
/*     */     
/*  67 */     if ((fileId == 0) && (version == 0)) {
/*  68 */       result[0] = this.defaultFileId;
/*  69 */       result[1] = this.defaultVersion;
/*     */     } else {
/*  71 */       result[0] = fileId;
/*  72 */       result[1] = version;
/*     */     }
/*     */     
/*  75 */     return result;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public InputStream getBlobInputStream(int fileId, int version)
/*     */     throws ServiceException, InvalidPatchReferenceException
/*     */   {
/*  83 */     if ((fileId == 0) && (version == 0)) {
/*  84 */       fileId = this.defaultFileId;
/*  85 */       version = this.defaultVersion;
/*     */     }
/*     */     try
/*     */     {
/*  89 */       Document doc = (Document)this.mbox.getItemRevision(this.opContext, fileId, MailItem.Type.DOCUMENT, version);
/*     */       
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  95 */       if (doc == null) {
/*  96 */         throw new InvalidPatchReferenceException("Reference to non-existing version " + version + " of document " + fileId);
/*     */       }
/*     */       
/*     */ 
/* 100 */       return doc.getContentStream();
/*     */     }
/*     */     catch (MailServiceException.NoSuchItemException e) {
/* 103 */       throw new InvalidPatchReferenceException("Reference to non-existing document: " + fileId + " (version: " + version + ")", e);
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/octosync/BlobAccessViaMailbox.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */